<?php
class Admin_payments_model extends CI_Model {

	function __construct(){
		parent::__construct();
	}
	//retrieve all data
	function listPayments(){
		$this->_builQueryWhere();
		return $this->db->get('mlme_orders tbl')->num_rows;
	}
	//to be used in pagination
	function listPayments_limited( $start_row=0, $limit=100 ){
		$this->_builQueryWhere();
		$this->db->select('tbl.*,b.firstname as userfname,b.lastname as userlname, c.name as prodname');
		$this->db->join('mlme_users b', 'tbl.userid = b.userid', 'LEFT');
		$this->db->join('mlme_products c', 'tbl.productid = c.productid', 'LEFT');
		$this->db->limit($limit ,$start_row);
		return $this->db->get('mlme_orders tbl');
	}
	//function to use in searching or filtering data
	//author: lalene@advanzweb.com

	function _builQueryWhere(){
		$filter = $this->input->post('search_text');
		if ($filter){
			$key	= $this->Quote('%'.mysql_real_escape_string( trim( strtolower( $filter ) ) ).'%');
			$where = array();
			$where[] = 'LOWER(tbl.order_number) LIKE '.$key;
			$this->db->where('('.implode(' OR ', $where).')');
       	}
	}

	/**
	* Get a quoted database escaped string
	*
	* @param	string	A string
	* @param	boolean	Default true to escape string, false to leave the string unchanged
	* @return	string
	* @access public
	*/
	function Quote( $text, $escaped = true )
	{
		return '\''.($escaped ? mysql_real_escape_string( $text ) : $text).'\'';
	}
}